<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="iwpl.project.entities.Customers"%>
<%@page import="iwpl.project.dao.CustomersDAO"%>
<%@page import="iwpl.project.dao.ApartmentsDAO"%>
<%@page import="iwpl.project.entities.Apartments"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Iterator"%>
<%@ page import="java.text.*,java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
<script type="text/javascript" src="js/datepicker.js">
</script>
<script src="js/jquery-Source.js"></script>
<script type="text/javascript" src="js/datetimepicker_css.js"></script>

<link rel="stylesheet" href="css/rfnet.css" type="text/css" />
<script type="text/javascript" src="js/jquery-Validation.js"></script>
<script type="text/javascript">
  $(document).ready(function()
  {
    $("#commentForm").validate();
  });
  </script>
<link rel="stylesheet" href="css/CommonCSS.css" type="text/css"></link>
<script type="text/javascript">			
	function Cancel()
	{
		location.href="/DepartmentManage/Manage_Customer.jsp";
	}			
</script>
</head>
<body>
<%
	String sex="false";
	String IsOwner="false";
	Customers cus = null;
	CustomersDAO dao = new CustomersDAO();
	
	try {
		String sCusID = request.getParameter("id");
		if(sCusID != null)
			cus = dao.findById(Integer.parseInt(sCusID));
			sex=cus.getSex();
			IsOwner=cus.getHost();	
			} catch (Exception e) {
			
		}
	%>
<form class="cmxform" id="commentForm" name="frm1" method="post" action="./servlet/CUSTOMER_Servlet">
	<div>
	<div align="center"> 
		<p style="margin:0px auto; font-family:verdana; font-weight:bold;">Customer Management</p>
	</div>
		<table style="width:350px;height:auto;margin:0 auto">
			<%
				if(cus!=null)
				{		
					SimpleDateFormat sd=new SimpleDateFormat("MM-dd-yyyy");
					String result = sd.format(cus.getBirthday());			
			%>
			<tr>				
				<td>
					<input type="hidden" name="txtID" style="width:250px" value="<%=request.getParameter("id")%>"/>
				</td>
			</tr>
			<tr>
			 <td>Full name </td>
				<td>
					<input type="text" name="txtCus_Name" style="width:250px" class="required" value="<%=cus.getFullName()%>"/>
				</td>
			</tr>
			<tr>
			 <td>Phone</td>
				<td>
					<input type="text" name="txtPhone" style="width:250px" class="required number" maxlength="24" minlength="10" value="<%=cus.getPhone()%>"/>
				</td>
			</tr>
			<tr>
			 <td>Sex</td>
				<td>
					<%if(sex=="true"){ %>
					<input type="checkbox" name="chkSex" checked="checked"/>
					<%}else {%>
						<input type="checkbox" name="chkSex" />
					<%} %>
				</td>
			</tr>
			<tr>			
		  		 <td>Birth Date</td>
                 <td width="200px">
                     <input type="text" name="txtBirthDate" maxlength="25" size="25" readonly="readonly" value="<%=result%>" class="required"/> <a href="javascript:NewCssCal('txtBirthDate','mmddyyyy')"><img
                         src="images/cal.gif" width="16" height="16" alt="Pick a date"></a>
                 </td>                              
             </tr>
			<tr>
			 <td>Address</td>
				<td>
					<input type="text" name="txtAddress" style="width:250px" class="required" value="<%=cus.getAddress()%>"/>
				</td>
			</tr>
			<tr>
			<td>Department</td>
				<td>
				<select name="cboApartment" style="width:256px">
			<%
				ApartmentsDAO objDao= new ApartmentsDAO();
				List<Apartments> lstApart = objDao.findAll();
				for( Iterator<Apartments> it = lstApart.iterator(); it.hasNext(); ) {
							Apartments aPART = (Apartments)it.next();
			 %> 				
			<option value="<%=aPART.getId()%>" label="<%=aPART.getApartmentNumber()%>"> 
			</option>
			<%} %>
			</select>
			</td>
			</tr>
			<tr>
			 <td>Owner</td>
				<td>
					<%if(IsOwner=="true"){ %>
					<input type="checkbox" name="chkSex" checked="checked"/>
					<%}else {%>
						<input type="checkbox" name="chkSex" />
					<%} %>
				</td>
			</tr>		
			<tr>
				<td>
					<button name="btnSave" type="submit" style="width:70px;height:25px;margin-right:5px;text-align:center" value="btnSave" class="submit">Save</button>
				</td>
				<td>
					<button name="btnCancel" style="width:70px;height:25px;margin-left:5px;text-align:center" class="submit" onclick="Cancel();">Cancel</button>
				</td>
			</tr>	
			<%		
				}
			 %>		
		</table>
</div>
</form>
</body>
</html>